
var express = require('express');
var http = require('http');
var path = require('path');
var app = express();
var fs = require('fs');

app.set('port', process.env.PORT || 9999);
app.use('/',express.static(path.join(__dirname, '/')));

function routeData(){
	fs.readdir('fake_data',function(err,data){
		var len = data.length;
		for (var i =0; i<len; i++){
			!function(name){
				app.get('/getdata/'+name, function(req, res){
					fs.readFile('fake_data/'+name,'utf-8',function(err,data2){
						var json = JSON.parse(data2);
						res.json(json);
						res.end();
					});
				})
			}(data[i]);
		}
	});
}
routeData();

 
/*app.get('/getdata',function(req, res){
	fs.readFile('data.json','utf-8',function(err,data){
		var json = JSON.parse(data);
		res.json(json);
		res.end();
	});
});
*/

app.get('/',function(req, res){
	res.redirect('/index.html');
});

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});